<?php /*
Please design and code the above form, functionality in php. 
You allowed to use any php functions. 
For the charts try to use CSS, PHP to bring out this.
*/
//error_reporting(0);
$testing = mysql_connect("localhost","root",""); // DB details
mysql_select_db("php_studentform");
?>

<form action="ex4.php" method="post">
<label>Student Name</label>
<input type="text" name="studentname" value=" " /><br><br>
<label style="padding-right:7px;">Father Name</label>
<input type="text" name="fathername" value=" " /><br><br>
<label>Mother Name</label>
<input type="text" name="mothername" value=" " /><br><br>
<label style="padding-right:32px;">Marks</label>
<label>E</label>
<input type="text" name="english" value=" " />
<label>T</label>
<input type="text" name="tamil" value=" " />
<label>M</label>
<input type="text" name="maths" value=" " />
<label>S</label>
<input type="text" name="science" value=" " />
<label>S.S</label>
<input type="text" name="sscience" value=" " /><br><br>
<input type="submit" name="submit-entry" value="Entry" />
</form>

<?php
if(isset($_POST['submit-entry']))
{
//post varible declare
$studentname = $_POST['studentname'];
$fathername = $_POST['fathername'];
$mothername = $_POST['mothername'];
$english = $_POST['english'];
$tamil = $_POST['tamil'];
$maths = $_POST['maths'];
$science = $_POST['science'];
$sscience = $_POST['sscience'];
//mysql connection

$fields = "INSERT INTO details(studentname, fathername, mothername, english, tamil, maths, science, sscience) VALUES ('$studentname', '$fathername', '$mothername', '$english', '$tamil', '$maths', '$science', '$sscience')";
//echo $fields;
$check = mysql_query($fields);
//values get form database



if($check)
{
 echo 'add';
}
else
{
echo 'error';
}
}
//mysql_close($testing);
?>

<?php
$test = mysql_query("SELECT * from details");	
?>
<table border="1" cellspacing="0">
<tr>
<td>
<?php echo 'Name';?>
</td>
<td>
<?php echo 'Father Name';?>
</td>
<td>
<?php echo 'Mothername';?>
</td>
<td>
<?php echo 'English';?>
</td>
<td>
<?php echo 'Tamil';?>
</td>
<td>
<?php echo 'Maths';?>
</td>
<td>
<?php echo 'Science'; ?>
</td>
<td>
<?php echo 'Social Science';
?>
</td></tr> <?php
$eng=0; $counter=0; $ta=0;$ma=0; $sc=0;$ssc=0;
while($row = mysql_fetch_array($test))
{
 ?>
 <tr><td>
<?php
echo $row['studentname']; ?>
</td>
<td>
<?php echo $row['fathername'];?>
</td>
<td>
<?php echo $row['mothername'];?>
</td>
<td>
<?php echo $row['english'];
$eng =$eng + $row['english'];
?>
</td>
<td>
<?php echo $row['tamil']; $ta =$ta + $row['tamil'];?>
</td>
<td>
<?php echo $row['maths']; $ma =$ma + $row['maths'];?>
</td>
<td>
<?php echo $row['science'];$sc =$sc + $row['science'];?>
</td>
<td>
<?php echo $row['sscience']; $ssc =$ssc + $row['sscience'];
$counter++;
}

?>
</td></tr>
</table>
<div class="" style="float:right;">
<?php 
echo 'Overall student marks'.'<br>';
$collection = array('English'=>$eng,'Tamil'=>$ta, 'Maths'=>$ma, 'science'=>$sc, 'sscience'=>$ssc);
//print_r($collection);
//echo $counter; 
foreach($collection as $key=>$value)
{
$percentage = $value/$counter;
?>
<div class="" style="float:left; width:50px;">
<?php echo $key .'<br>'; ?>
</div>
<div class="" style="width:100px;border:solid 1px; float:left; height:20px;">
<div class="" style="width:<?php echo $percentage; ?>px;background-color:#00B5FF; height:20px;">
</div>
</div></br></br>
<?php
//echo $percentage .'<br>';
}

?>
</div>










